/*
 * $Id: CmdLineOptions.java 3 2007-12-07 01:24:30Z rasan.rasch $
 *
 * Copyright (c) 2002-2006 UC Regents
 * 
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee, provided
 * that (i) the above copyright notices and this permission notice appear in
 * all copies of the software and related documentation, and (ii) the names
 * of the UC Regents and the University of California are not used in any
 * advertising or publicity relating to the software without the specific,
 * prior written permission of the University of California.
 * 
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY
 * THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE
 * OR PERFORMANCE OF THIS SOFTWARE.
 */

package org.cdl.noid;

import jargs.gnu.CmdLineParser;
import jargs.gnu.CmdLineParser.Option;

/** 
 * CmdLineOptions is class to parse command line options
 * for the NoidTest program.
 * 
 * @author Rasan Rasch (rasan@nyu.edu)
 * @version $Revision: 3 $
 */
public class CmdLineOptions implements Options {
	
	String[] args;
	CmdLineParser parser;
	
	Boolean debug;
	Boolean help;
	Boolean version;
	Integer locktest;
	String dbdir;

	/** 
	 * Construct a new CmdLineOptions object.
	 * 
	 * @param args command line arguments.
	 */
	public CmdLineOptions(String[] args) {
		this.args = args;
		this.parser = new CmdLineParser();
	}

	/** 
	 * Parse command line options.
	 */
	public void parseOptions() {
		
		Option debugOpt    = parser.addBooleanOption("debug");
		Option locktestOpt = parser.addIntegerOption("locktest");
		Option dbdirOpt    = parser.addStringOption("dbdir");
		Option versionOpt  = parser.addBooleanOption("version");
		Option helpOpt     = parser.addBooleanOption("help"); 

		try {
			parser.parse(args);
		} catch (CmdLineParser.OptionException e) {
			System.exit(2);
		}

		debug    = (Boolean) parser.getOptionValue(debugOpt, Boolean.FALSE);
		help     = (Boolean) parser.getOptionValue(helpOpt, Boolean.FALSE);
		version  = (Boolean) parser.getOptionValue(versionOpt, Boolean.FALSE);
		locktest = (Integer) parser.getOptionValue(locktestOpt);
		dbdir    = (String) parser.getOptionValue(dbdirOpt);

	}

	/** 
	 * Check if debugging messages should be printed.
	 * 
	 * @return <code>true</code> if <code>--debug</code> specified on
	 *         command line; <code>false</code> otherwise
	 */
	public boolean getDebug() {
		return debug.booleanValue();
	}

	/** 
	 * Check if help message should be displayed.
	 * 
	 * @return <code>true</code> if <code>--help</code> specified on
	 *         command line; <code>false</code> otherwise
	 */
	public boolean getHelp() {
		return help.booleanValue();
	}

	/** 
	 * Check if noid version should be displayed.
	 * 
	 * @return <code>true</code> if <code>--version</code> flag
	 *         specified on command line; <code>false</code>
	 *         otherwise
	 */
	public boolean getVersion() {
		return version.booleanValue();
	}
	
	/** 
	 * Return value of lock test.
	 * 
	 * @return Integer representing value specified by
	 *         <code>--locktest</code> on command line; if no value
	 *         given return <code>null</code>
	 */
	public Integer getLocktest() {
		return locktest;
	}
	
	/** 
	 * Get path for minter database directory.
	 * 
	 * @return path of db directory specified by
	 *         <code>--dbdir</code>; <code>null<code> if no value
	 *         given on the command line
	 */
	public String getDbdir() {
		return dbdir;
	}

}
